﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>Until - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The Until statement applies a condition to the continuation of a Loop or For-loop." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Until</h1>

<p>根据条件判断是否继续执行 Loop 或 For 循环.</p>

<pre class="Syntax"><span class="func">Loop</span> {
    ...
} <span class="func">Until</span> <i>Expression</i></pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>Expression</dt>
  <dd><p>任何有效的<a href="../Variables.htm#Expressions">表达式</a>.</p></dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>如果表达式被括在括号中, <code>Until</code> 后的空格和制表是可选的, 如 <code>until(expression)</code> 所示.</p>
<p>表达式在每次迭代后求值一次, 即使使用了 <a href="Continue.htm">continue</a> 也会进行计算. 如果表达式计算结果为 false(即为空字符串或数值 0), 循环继续; 否则循环被打破且跳到 <i>Until</i> 后面一行继续执行.</p>
<p>Loop Until 是下列结构的简写形式:</p>
<pre>Loop {
    ...
    if (<i>Expression</i>)
        break
}</pre>
<p>不过, Loop Until 通常更容易理解, 且与上面不同的是, 可以与单行动作一起使用. 例如:</p>
<pre>Loop
    x *= 2
Until x &gt; y</pre>
<p><i>Until</i> 可以使用在任何 Loop 或 For 循环中. 例如:</p>
<pre>Loop Read, A_ScriptFullPath
    lines .= A_LoopReadLine . "`n"
Until A_Index=5  <em>; 读取前五行.</em>
MsgBox lines
</pre>
<p>如果 <a href="../Variables.htm#Index">A_Index</a> 用在 <i>Expression</i> 中, 那么它的值为刚结束的那次循环的索引.</p>

<h2 id="Related">相关</h2>
<p><a href="Loop.htm">Loop</a>, <a href="While.htm">While-loop</a>, <a href="For.htm">For-loop</a>, <a href="Break.htm">Break</a>, <a href="Continue.htm">Continue</a>, <a href="Block.htm">区块</a>, <a href="LoopFiles.htm">Files-and-folders loop</a>, <a href="LoopReg.htm">Registry loop</a>, <a href="LoopRead.htm">File-reading loop</a>, <a href="LoopParse.htm">Parsing loop</a>, <a href="If.htm">If (表达式)</a></p>

</body>
</html>